home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / TUTORIAL.BIN / SoundPlayer.class (.txt) < prev    next >
Encoding:
Java Class File  |  1996-12-16  |  2.5 KB  |  107 lines

  1. package symantec.itools.multimedia;
  2.  
  3. import java.io.IOException;
  4. import java.io.InputStream;
  5. import java.net.MalformedURLException;
  6. import java.net.URL;
  7. import java.net.URLConnection;
  8. import java.util.Vector;
  9. import sun.audio.AudioStream;
  10.  
  11. public class SoundPlayer {
  12.    private Vector clips = new Vector();
  13.    private boolean sync = true;
  14.    private SoundViewerThread spt;
  15.    private int repeatCt = 1;
  16.    public static final int INFINITE = -1;
  17.  
  18.    public void setSyncMode(boolean var1) {
  19.       this.sync = var1;
  20.       if (this.spt != null) {
  21.          this.spt.doSync(var1);
  22.       }
  23.  
  24.    }
  25.  
  26.    public boolean getSyncMode() {
  27.       return this.sync;
  28.    }
  29.  
  30.    public void setRepeat(int var1) {
  31.       this.repeatCt = var1;
  32.    }
  33.  
  34.    public int getRepeat() {
  35.       return this.repeatCt;
  36.    }
  37.  
  38.    public void addURL(URL var1) {
  39.       InputStream var2 = null;
  40.  
  41.       try {
  42.          try {
  43.             URLConnection var5 = var1.openConnection();
  44.             var5.setAllowUserInteraction(true);
  45.             var2 = var5.getInputStream();
  46.             AudioStream var6 = new AudioStream(var2);
  47.             this.clips.addElement(new SoundViewerItem(var6.getData(), (int)((double)var6.getLength() / (double)7168.0F * (double)1000.0F)));
  48.          } finally {
  49.             if (var2 != null) {
  50.                var2.close();
  51.             }
  52.  
  53.          }
  54.  
  55.       } catch (IOException var10) {
  56.       }
  57.    }
  58.  
  59.    public void addStringURL(String var1) {
  60.       try {
  61.          this.addURL(new URL(var1));
  62.       } catch (MalformedURLException var2) {
  63.       }
  64.    }
  65.  
  66.    public void setURLList(URL[] var1) {
  67.       this.clips.removeAllElements();
  68.  
  69.       for(int var2 = 0; var2 < var1.length; ++var2) {
  70.          this.addURL(var1[var2]);
  71.       }
  72.  
  73.    }
  74.  
  75.    public URL[] getURLList() {
  76.       int var1 = this.clips.size();
  77.       URL[] var2 = new URL[var1];
  78.  
  79.       for(int var3 = 0; var3 < var1; ++var3) {
  80.          var2[var3] = (URL)this.clips.elementAt(var3);
  81.       }
  82.  
  83.       return var2;
  84.    }
  85.  
  86.    public void play() {
  87.       this.spt = new SoundViewerThread(this.clips, this.sync, this.repeatCt);
  88.       this.spt.start();
  89.    }
  90.  
  91.    public void stop() {
  92.       if (this.spt != null) {
  93.          this.spt.doStop();
  94.       }
  95.  
  96.    }
  97.  
  98.    public void stop(int var1) {
  99.       try {
  100.          Thread.sleep((long)var1);
  101.       } catch (InterruptedException var2) {
  102.       }
  103.  
  104.       this.stop();
  105.    }
  106. }
  107.